<template>
  <div class="app-container">
    <!--工具栏-->
    <div v-if="showType==0" class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">事件描述</label>
        <el-input v-model="query.eventDesc" clearable placeholder="事件描述" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">测评点位</label>
        <el-input v-model="query.linear" clearable placeholder="测评点位" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">问题明细</label>
        <el-input v-model="query.evaluationDtl" clearable placeholder="问题明细" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />

        <!-- <label class="el-form-item-label">姓名</label>
        <el-input v-model="query.name" clearable placeholder="姓名" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <!-- <label class="el-form-item-label">手机号</label> -->
        <!-- <el-input v-model="query.phone" clearable placeholder="手机号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <label class="el-form-item-label">事件处理状态</label>
        <el-select v-model="query.status" clearable size="small" placeholder="处理情况" class="filter-item" style="width: 150px" @change="crud.toQuery">
          <el-option v-for="item in dict.event_status" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <label class="el-form-item-label">来源</label>
        <el-select v-model="query.souce" clearable size="small" placeholder="来源" class="filter-item" style="width: 150px" @change="crud.toQuery">
          <el-option v-for="item in dict.event_souce" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <label class="el-form-item-label">责任单位</label>
        <el-input v-model="query.rpunit" clearable placeholder="责任单位" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <!-- <label class="el-form-item-label">任务</label>
        <el-input v-model="query.task" clearable placeholder="任务" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <label class="el-form-item-label">上报时间</label>
        <date-range-picker v-model="query.createTime" clearable placeholder="上报时间" style="width: 220px;height:33px" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission">
        <template slot="right">
          <el-button
            v-permission="permission.import"
            class="filter-item"
            size="mini"
            type="warning"
            icon="el-icon-download"
            @click="doImport"
          >导入</el-button>
          <el-button
            :loading="crud.downloadLoading"
            :disabled="!crud.data.length"
            class="filter-item"
            size="mini"
            type="warning"
            icon="el-icon-download"
            @click="myDoExport"
          >导出</el-button>
          <el-button
            v-permission="permission.assignAduit"
            class="filter-item"
            size="mini"
            type="warning"
            @click="doBatchAduit"
          >批量指派审核</el-button>
          <el-button
            v-permission="permission.assign"
            class="filter-item"
            size="mini"
            type="warning"
            @click="doBatchZhiPai"
          >批量指派</el-button>

          <el-button
            v-permission="permission.batchfuhe"
            class="filter-item"
            size="mini"
            type="warning"
            @click="doBatchFuHe"
          >批量复核</el-button>
          <el-button
            v-permission="permission.batchshenpi"
            class="filter-item"
            size="mini"
            type="warning"
            @click="doBatchShenPi"
          >批量审批</el-button>
        </template>
      </crudOperation>
      <!-- 导入 -->
      <zdyDialog
        :visible.sync="importVisible"
        dialog-title="导入zip"
        :append-to-body="true"
        :width="'70%'"
        top="15vh"
        max-height="66vh"
        @onSubmit="onImportSubmit"
      >
        <div
          v-loading="importfLoading"
        >
          <el-row>
            <el-col :span="24" style="display: flex; justify-content: flex-start;">
              <span style="width: 120px;height: 50px;">来源：</span>
              <el-select v-model="importf.souce" filterable placeholder="请选择">
                <el-option
                  v-for="item in dict.event_souce"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24" style="display: flex; justify-content: flex-start;">
              <span style="width: 120px;">附件：</span>
              <zdyUpload
                ref="zdyUpload"
                :is-report="true"
                :file-size="6000000"
                :file-list="importf.uploadList"
                :file-type="['zip']"
                :limit="1"
                :my-upload-file-url="httpRequest"
                @handleRemove="handleRemovezip"
                @handleSuccess="handleSuccesszip"
              />
            </el-col>
          </el-row>
        </div>
      </zdyDialog>
      <!-- 争议 -->
      <zdyDialog
        :visible.sync="eventVisible"
        :dialog-title="typeText"
        :append-to-body="true"
        :width="'70%'"
        top="15vh"
        max-height="66vh"
        @onSubmit="onDisputeSubmit"
      >
        <div v-if="eventVisible">
          <el-row v-if="typeText=='延期'">
            <el-col :span="24" style="display: flex; justify-content: flex-start;margin-bottom: 20px;">
              <span style="width: 120px;">{{ typeText }}时间：</span>
              <el-date-picker v-model="event.extensionTime" placeholder="请选择" type="date" value-format="yyyy-MM-dd" :picker-options="pickerOptions" />
            </el-col>
          </el-row>
          <el-row v-if="typeText == '处理'">
            <el-col :span="24" style="display: flex; justify-content: flex-start;margin-bottom: 20px;">
              <span style="width: 120px;">问题图片：</span>
              <div class="question-img-box">
                <el-image
                  v-for="item in questionList"
                  :key="item.id"
                  class="question-img"
                  :src="host+item.url"
                  :preview-src-list="[host+item.url]"
                />
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24" style="display: flex; justify-content: flex-start;margin-bottom: 20px;">
              <span style="width: 120px;">{{ typeText }}说明：</span>
              <el-input v-model="event.explain" placeholder="请输入" :rows="3" type="textarea" />
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24" style="display: flex; justify-content: flex-start;margin-bottom: 20px;">
              <span style="width: 120px;">{{ typeText }}附件：</span>
              <zdyUpload
                v-if="typeText!=='延期'"
                :file-type="['png', 'jpg', 'jpeg']"
                :file-list="event.uploadList"
                @handleRemove="handleRemovevent"
                @handleSuccess="handleSuccessevent"
              />

              <el-upload
                v-if="typeText=='延期'"
                ref="upload"
                :file-list="event.uploadList"
                :headers="headers"
                :on-success="handleSuccessevent"
                :on-remove="handleRemovevent"
                :action="urlActionUrl"
              >
                <div class="eladmin-upload"><i class="el-icon-upload" /> 添加文件</div>
                <div slot="tip" class="el-upload__tip">问题整改申请延期，一定要附pdf格式的情况说明（单位一把手签字，盖单位公章），并附word版</div>
              </el-upload>
            </el-col>
          </el-row>
        </div>
      </zdyDialog>
      <!-- 二次督办 -->
      <zdyDialog
        :visible.sync="againVisible"
        dialog-title="二次督办"
        :append-to-body="true"
        :width="'50%'"
        top="15vh"
        max-height="66vh"
        @onSubmit="onAgainSubmit"
      >
        <el-form ref="againform" :model="againform" size="small" label-width="80px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="整改时限">
                <el-select v-model="againform.deadline">
                  <el-option v-for=" i in numArr" :key="i" :label="i+'天'" :value="i" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </zdyDialog>
      <!-- 指派 -->
      <zdyDialog
        :visible.sync="assignVisible"
        dialog-title="指派"
        :append-to-body="true"
        :width="'50%'"
        top="15vh"
        max-height="66vh"
        @onSubmit="onAssignSubmit"
      >
        <el-form ref="assignform" size="small" label-width="80px" :model="assignform" :rules="assignRules">
          <el-row>
            <el-col :span="24">
              <el-form-item label="责任单位" prop="deptName">
                <div style="display:flex;">
                  <el-input v-model="assignform.deptName" disabled />
                  <el-button type="parimary" @click="multiple=false;deptVisible=true">选择</el-button>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="帮创单位">
                <div style="display:flex;">
                  <!-- <el-input v-model="form.taskName" disabled  /> -->
                  <div class="groupxzzy">
                    <el-tag v-for="item in assignform.assistanceUnit" :key="item.id" closable @close="handleClose(item)">
                      {{
                        item.name }}
                    </el-tag>
                  </div>
                  <el-button type="parimary" @click="multiple=true;deptVisible=true">选择</el-button>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </zdyDialog>
      <!--新增编辑组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="50%" top="3%">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px" style="height: 68vh; overflow-y: scroll;">
          <el-row>
            <!--<el-col :span="12">
              <el-form-item label="id" prop="id">
                <el-input v-model="form.id" />
              </el-form-item> -->
            <!-- <el-form-item label="事件标题" prop="title">
                <el-input v-model="form.title" />
              </el-form-item>
            </el-col>-->
            <el-col :span="24">
              <el-form-item label="测评点位" prop="linearName">

                <div style="display:flex;">
                  <el-input v-model="form.linearName" disabled />
                  <el-button type="parimary" @click="lineVisible=true">选择</el-button>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="姓名">
                <el-input v-model="form.name" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="手机号" prop="phone">
                <el-input v-model.number="form.phone" />
              </el-form-item>
            </el-col>
          </el-row> -->
          <el-row>
            <el-col :span="24">
              <el-form-item label="责任单位">
                <div style="display:flex;">
                  <el-input v-model="form.deptName" disabled />
                  <el-button type="parimary" @click="multiple=false;deptVisible=true">选择</el-button>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="来源" prop="souce">
                <el-select v-model="form.souce" filterable placeholder="请选择">
                  <el-option
                    v-for="item in dict.event_souce"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="form.souce==7||form.souce==8" label="回访次数" prop="visitsNum">
                <el-input v-model="form.visitsNum" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <!-- <el-col :span="12">
              <el-form-item label="来源" prop="souce">
                <el-select v-model="form.souce" filterable placeholder="请选择">
                  <el-option
                    v-for="item in dict.event_souce"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value" />
                </el-select>
              </el-form-item>
            </el-col> -->
            <!-- <el-col :span="12">
              <el-form-item label="任务" prop="taskName">
                <div style="display:flex;">
                  <el-input v-model="form.taskName" disabled />
                  <el-button type="parimary" @click="taskVisible=true">选择</el-button>
                </div>
              </el-form-item>
            </el-col> -->

            <el-col :span="24">
              <el-form-item label="问题明细" prop="evaluationDtlName">
                <div style="display:flex;">
                  <el-input v-model="form.evaluationDtlName" disabled />
                  <el-button type="parimary" @click="evaluationDtlVisible=true">选择</el-button>
                </div>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="帮创单位">
                <div style="display:flex;">
                  <!-- <el-input v-model="form.taskName" disabled  /> -->
                  <div class="groupxzzy">
                    <el-tag v-for="item in form.assistanceUnit" :key="item.id" closable @close="handleClose(item)">
                      {{
                        item.name }}
                    </el-tag>
                  </div>
                  <el-button type="parimary" @click="multiple=true;deptVisible=true">选择</el-button>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="事件地址">
                <el-input v-model="form.point" placeholder="请输入" clearable />
                <AmapSearch @mapParams="getMapParams" />
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-row>
            <el-col :span="24">
              <el-form-item label="事件描述">
                <el-input v-model="form.eventDesc" type="textarea" :rows="4" />
              </el-form-item>
            </el-col>
          </el-row> -->
          <el-row>
            <el-col :span="24">
              <span style="position: relative; top: 22px; color: red;">*</span>
              <el-form-item label="事件图片" prop="uploadList">
                <zdyUpload
                  :file-list="form.uploadList&&form.uploadList.filter(i=>i.type==1)"
                  :file-type="['png', 'jpg', 'jpeg']"
                  @handleRemove="handleRemove"
                  @handleSuccess="handleSuccess"
                />

                <!-- <el-upload
                  :file-list="form.uploadList&&form.uploadList.filter(i=>i.type==1)"
                  ref="upload"
                  :limit="10"
                  :headers="headers"
                  :on-success="handleSuccess"
                  :on-remove="handleRemove"
                  :action="urlActionUrl"
                >
                  <div class="eladmin-upload"><i class="el-icon-upload" /> 添加文件</div>
                  <div slot="tip" class="el-upload__tip">可上传任意格式文件</div>
                </el-upload> -->

              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" tooltip-effect="dark" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" fixed="left" />
        <!-- <el-table-column prop="id" label="id" /> -->
        <!-- <el-table-column prop="title" label="事件标题" show-overflow-tooltip  width="250px"/> -->
        <el-table-column prop="eventDesc" label="事件描述" show-overflow-tooltip width="250px">
          <!-- <template slot-scope="scope">
            {{ scope.row.linear&&scope.row.linear.name }}
          </template> -->
        </el-table-column>
        <el-table-column prop="point" label="事件地址" show-overflow-tooltip width="250px" />
        <el-table-column label="责任单位" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.rpunit&&scope.row.rpunit.name }}
          </template>
        </el-table-column>
        <el-table-column label="帮创单位" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.assistanceUnit.map(i=>i.name).join('，') }}
          </template>
        </el-table-column>
        <el-table-column prop="souce" label="来源">
          <template slot-scope="scope">
            {{ dict.label.event_souce[scope.row.souce] }}
          </template>
        </el-table-column>
        <el-table-column prop="linearId" label="测评点位" show-overflow-tooltip width="250px">
          <template slot-scope="scope">
            {{ scope.row.linear&&scope.row.linear.name }}
          </template>
        </el-table-column>
        <el-table-column prop="title" label="点位类型" show-overflow-tooltip width="250px">
          <template slot-scope="scope">
            {{ scope.row.evaluationDtl&&scope.row.evaluationDtl.evaluation.evaluationItems }}
          </template>
        </el-table-column>
        <el-table-column label="问题明细" show-overflow-tooltip width="350px">
          <template slot-scope="scope">
            {{ scope.row.evaluationDtl&&scope.row.evaluationDtl.name }}
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="上报时间" show-overflow-tooltip width="150px">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="name" label="姓名" />
        <el-table-column prop="phone" label="手机号"  width="150px"/> -->
        <!-- <el-table-column prop="status" label="事件处理状态">
          <template slot-scope="scope">
            {{ dict.label.event_status[scope.row.status] }}
          </template>
        </el-table-column> -->
        <!-- <el-table-column prop="longitude" label="经度" />
        <el-table-column prop="latitude" label="维度" /> -->
        <!-- <el-table-column prop="eventDesc" label="事件描述" show-overflow-tooltip /> -->
        <el-table-column prop="extensionTime" label="延期时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.extensionTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="事件处理状态" fixed="right">
          <template slot-scope="scope">
            {{ dict.label.event_status[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','tEvent:edit','tEvent:del']" label="操作" width="350px" align="center" fixed="right">
          <template slot-scope="scope">
            <div style="display: flex; ">
              <el-button
                class="filter-item"
                size="mini"
                type="warning"
                @click="showType=1;eventId=scope.row.id"
              >查看</el-button>
              <el-button
                v-if="(scope.row.status== 0||scope.row.status== 12)&&checkPermission(permission.assign)"
                class="filter-item"
                size="mini"
                type="warning"
                @click="assignVisible=true; eventId=scope.row.id;zhipaiBatch = false "
              >指派</el-button>
              <el-button
                v-if="(scope.row.status==5||scope.row.status==6||scope.row.status==7)&&checkPermission(permission.aduit)"
                class="filter-item"
                size="mini"
                type="warning"
                @click="showType=1;eventId=scope.row.id;allpending=1;aduitType=2"
              >审核</el-button>
              <el-button
                v-if="(scope.row.status==8||scope.row.status==9||scope.row.status==10)&&(scope.row.status==9||scope.row.rpunit&&scope.row.rpunit.id==user.dept.id )&&checkPermission(permission.againaduit)"
                class="filter-item"
                size="mini"
                type="warning"
                @click="showType=1;eventId=scope.row.id;allpending=1;aduitType=1"
              >复核</el-button>
              <udOperation
                v-if="scope.row.status==0"
                style="margin-right: 4px;"
                :data="scope.row"
                :permission="permission"
              />
              <el-button
                v-if="(scope.row.status==2)&&(scope.row.rpunit&&scope.row.rpunit.id==user.dept.id )&&checkPermission(permission.extension)"
                class="filter-item"
                size="mini"
                type="warning"
                @click="typeText='延期';eventVisible=true;eventId=scope.row.id"
              >延期</el-button>
              <el-button
                v-if="(scope.row.status==1)&&checkPermission(permission.dispute)"
                class="filter-item"
                size="mini"
                type="warning"
                @click="typeText='争议';eventVisible=true;eventId=scope.row.id"
              >争议</el-button>
              <el-button
                v-if="(scope.row.status==2||scope.row.status==4)&&(scope.row.rpunit&&scope.row.rpunit.id==user.dept.id )&&checkPermission(permission.deal)"
                class="filter-item"
                size="mini"
                type="warning"
                @click="handleShowDispose(scope.row)"
              >处理</el-button>
              <el-button
                v-if="(scope.row.status!=0&&scope.row.status!=12&&scope.row.status!=1&&scope.row.status!=5&&scope.row.status!=9)&&checkPermission(permission.print)"
                class="filter-item"
                size="mini"
                type="warning"
                @click="$refs.printPage.open(scope.row)"
              >打印督办单</el-button>
              <el-button
                v-if="(scope.row.status==11)&&checkPermission(permission.secondDo)"
                class="filter-item"
                size="mini"
                type="warning"
                @click="againVisible=true;eventId=scope.row.id"
              >二次督办</el-button>
              <el-button
                v-if="(scope.row.status==12)&&checkPermission(permission.assignAduit)"
                class="filter-item"
                size="mini"
                type="warning"
                @click="doToAduit(scope.row.id)"
              >指派审批</el-button>
              <el-button
                v-if="(scope.row.status==2||scope.row.status==8||scope.row.status==9||scope.row.status==10)&&checkPermission(permission.reminder)"
                class="filter-item"
                size="mini"
                type="warning"
                @click="doToReminder(scope.row.id)"
              >催办</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
    <selecrGroptLinearLane
      v-if="lineVisible"
      :dialog-visible.sync="lineVisible"
      title="选择线片港"
      @select="selectLine"
    />
    <selecrGroptTask
      v-if="taskVisible"
      :dialog-visible.sync="taskVisible"
      title="选择任务"
      @select="selectTask"
    />
    <selecrGropDept
      v-if="deptVisible"
      :dialog-visible.sync="deptVisible"
      title="选择单位"
      :multiple="multiple"
      :tag="tag"
      @select="selectDept"
    />
    <selecrGroptDtl
      v-if="evaluationDtlVisible"
      :dialog-visible.sync="evaluationDtlVisible"
      title="选择点位"
      @select="selectEvaluationDtl"
    />
    <!-- 查看 -->
    <tEventView v-else-if="showType==1" ref="information" :zyzid="eventId" :allpending="allpending" @back="goback" />
    <!-- 打印详情 -->
    <print-page ref="printPage" />
    <el-dialog
      width="30%"
      title="提示"
      :visible.sync="innerVisible"
      append-to-body
    >
      <el-form :model="passForm">
        <el-form-item label="不通过原因" label-width="120px">
          <el-input v-model="passForm.reason" autocomplete="off" type="textarea" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="doBatchNoPass">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { selectTEvent } from '@/api/system/tEvent'
import { checkPermission } from '../../../utils/permission'
import tEventView from './view.vue'
import printPage from './print.vue'
import AmapSearch from '@/components/AmapSearch/index.vue'
import crudTEvent from '@/api/system/tEvent'
import { isvalidPhone } from '@/utils/validate'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import selecrGroptDtl from './../components/selecrGroptDtl'
import selecrGroptLinearLane from './../components/selecrGroptLinearLane'
import selecrGroptTask from './../components/selecrGroptTask'
import selecrGropDept from './../components/selecrGropDept'
import DateRangePicker from '@/components/DateRangePicker'
import { getToken } from '@/utils/auth'
import { initData, download } from '@/api/data'
import { parseTime, downloadFile } from '@/utils/index'
import { mapGetters } from 'vuex'
const defaultForm = { id: null, title: null, linearId: null, linearName: null, taskName: null, evaluationDtlName: null, createTime: null, assistanceUnit: [], point: null, name: null, phone: null, status: null, longitude: null, latitude: null, eventDesc: null, extensionTime: null, rpunitId: null, souce: '2', taskId: null, deptName: null }
export default {
  name: 'TEvent',
  components: { pagination, crudOperation, rrOperation, udOperation, selecrGroptLinearLane, selecrGroptTask, selecrGropDept,
    AmapSearch, tEventView, printPage, DateRangePicker, selecrGroptDtl },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['event_status', 'event_souce'],
  cruds() {
    return CRUD({ title: '事件管理', url: 'api/tEvent', query: { createTime: [new Date().getFullYear() + '-01-01 00:00:00', new Date().getFullYear() + '-12-31 23:59:59'] }, idField: 'id', sort: 'createTime,desc', crudMethod: { ...crudTEvent }})
  },
  data() {
    // 自定义验证
    const validPhone = (rule, value, callback) => {
      if (!isvalidPhone(value)) {
        callback(new Error('请输入正确的11位手机号码'))
      } else {
        callback()
      }
    }
    return {
      host: process.env.VUE_APP_BASE_API,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now()
        }
      },
      numArr: [1, 2, 3, 4, 5, 6, 7, 8, 9],
      permission: {
        add: ['admin', 'tEvent:add'],
        edit: ['admin', 'tEvent:edit'],
        del: ['admin', 'tEvent:del'],
        assign: ['admin', 'tEvent:assign'],
        view: ['admin', 'tEvent:view'],
        extension: ['admin', 'tEvent:extension'],
        deal: ['admin', 'tEvent:deal'],
        dispute: ['admin', 'tEvent:dispute'],
        aduit: ['admin', 'tEvent:aduit'],
        againaduit: ['admin', 'tEvent:againaduit'],
        import: ['admin', 'tEvent:import'],
        secondDo: ['admin', 'tSupervisionForm:edit'],
        // secondDo: ['admin', 'tEvent:secondDo'],
        print: ['admin', 'tEvent:print'],
        assignAduit: ['admin', 'tEvent:assignAduit'],
        reminder: ['admin', 'tEvent:reminder'],
        batchfuhe: ['admin', 'tEvent:batchfuhe'],
        batchshenpi: ['admin', 'tEvent:batchshenpi']
      },
      headers: { 'Authorization': getToken() },
      urlActionUrl: process.env.VUE_APP_BASE_API + '/api/localStorage/addCustomPath',
      importf: {
        souce: '',
        uploadList: []
      },
      event: {
        explain: '',
        uploadList: []
      },
      questionList: [],
      showType: 0,
      allpending: 0,
      aduitType: 0,
      rules: {
        souce: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        visitsNum: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        linearName: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        // title: [
        //   { required: true, message: '不能为空', trigger: 'blur' }
        // ],
        evaluationDtlName: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
        // phone: [
        //   { required: false, trigger: 'blur', validator: validPhone }
        // ]
      },
      assignRules: {
        deptName: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        // { key: 'title', display_name: '事件标题' },
        { key: 'linear', display_name: '测评点位' },
        // { key: 'name', display_name: '姓名' },
        // { key: 'phone', display_name: '手机号' },
        { key: 'status', display_name: '事件处理状态' },
        { key: 'rpunit', display_name: '责任单位' },
        { key: 'evaluationDtlName', display_name: '问题明细' },
        { key: 'createTime', display_name: '上报时间' }
      ],
      againform: {
        deadline: 1
      },
      againVisible: false,
      importVisible: false,
      assignVisible: false,
      eventVisible: false,
      lineVisible: false,
      taskVisible: false,
      evaluationDtlVisible: false,
      deptVisible: false,
      multiple: false,
      tag: [],
      typeText: '争议',
      eventId: null,
      assignform: {
        assistanceUnit: [],
        deptName: ''
      },
      importfLoading: false,
      zhipaiBatch: false,
      zhipaiArr: [],
      passForm: {},
      innerVisible: false,
      dialogType: 1,
      listBatch: []
      // fileUrl:process.env.VUE_APP_BASE_API+'api/tEvent/importZip'
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ]) },
  created() {
    this.crud.optShow = {
      add: true,
      edit: true,
      del: true,
      download: false
    }
    if (this.$route.query.showType == 1) {
      this.eventId = this.$route.query.id
      this.showType = this.$route.query.showType
      this.allpending = 1
    }
    this.form.uploadList = []
    // this.query.createTime =[new Date().getFullYear()+'-01-01 00:00:00',new Date().getFullYear()+'-12-31 23:59:59']
  },
  methods: {
    handleShowDispose(row) {
      this.typeText = '处理'
      this.eventVisible = true
      this.eventId = row.id
      this.getQuestionList(row.id)
    },
    async getQuestionList(id) {
      const res = await selectTEvent({ id })

      if (res.attachments) {
        this.questionList = res.attachments.filter(item => {
          return item.type === 1
        })
      }
    },
    checkPermission,
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    // 地图选点回调
    getMapParams(data) {
      this.$set(this.form, 'point', data.locationName + data.address)
      // this.$set(this.form, 'familyProvince', data.provinceCode.slice(0, 2))
      // this.$set(this.form, 'familyCity', data.cityCode.slice(0, 4))
      // this.$set(this.form, 'familyTown', data.townCode)
      // this.$set(this.form, 'familyStreet', data.towncode)
      this.$set(this.form, 'latitude', data.latitude)
      this.$set(this.form, 'longitude', data.longitude)
    },
    doToAduit(id) {
      this.$confirm(`确认审核该条数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        crudTEvent.edit({ id: id, status: 1 }).then(res => {
          this.$message({
            type: 'success',
            message: '审核成功'
          })
          this.crud.refresh()
        })
      }).catch(() => {
      })
    },
    // 导出
    myDoExport() {
      this.crud.downloadLoading = true
      download('api/tEvent/download', { ...this.crud.getQueryParams(), sort: 'linear.name,desc' }).then(result => {
        downloadFile(result, '事件管理数据', 'xlsx')
        this.crud.downloadLoading = false
      }).catch(() => {
        this.crud.downloadLoading = false
      })
    },
    // 催办
    doToReminder(id) {
      this.$confirm(`确认是否催办该条数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        crudTEvent.pressToDo([id]).then(res => {
          this.$message({
            type: 'success',
            message: '催办成功'
          })
          this.crud.refresh()
        })
      }).catch(() => {
      })
    },
    // 选择线片
    selectLine(row) {
      this.lineVisible = false

      this.form.linear = row
      this.form.linearName = row.name
      this.form.linearId = row.id
    },
    // 选择任务
    selectTask(row) {
      this.taskVisible = false
      this.form.task = row
      this.form.taskName = row.linear.name
      this.form.taskId = row.id
    },
    // 选择点位
    selectEvaluationDtl(row) {
      this.evaluationDtlVisible = false
      this.form.evaluationDtl = row
      this.form.evaluationDtlName = row.name
      // this.form.taskName = row.linear.name
      // this.form.taskId = row.id
    },
    // 选择单位
    selectDept(row) {
      this.deptVisible = false
      if (this.assignVisible) {
        if (this.multiple) {
          // 组员
          this.assignform.assistanceUnit = row
        } else {
          // 组长
          this.assignform.rpunit = row
          this.assignform.deptName = row.name
        }
      } else {
        if (this.multiple) {
          // 组员
          this.form.assistanceUnit = row
        } else {
          // 组长
          this.form.rpunit = row
          this.form.deptName = row.name
        }
      }
    },
    // 删除已选单位
    handleClose(tag) {
      if (this.eventVisible) {
        this.form.assistanceUnit.splice(this.form.assistanceUnit.indexOf(tag), 1)
        this.tag = this.form.assistanceUnit
      } else if (this.assignVisible) {
        this.assignform.assistanceUnit.splice(this.assignform.assistanceUnit.indexOf(tag), 1)
        this.tag = this.assignform.assistanceUnit
      }
    },
    // 打开编辑弹窗前做的操作
    [CRUD.HOOK.beforeToEdit](crud, form) {
      this.form.linearName = form.linear && form.linear.name
      // this.form.taskName = form.task.workTasks
      this.form.deptName = form.rpunit && form.rpunit.name
      this.form.evaluationDtlName = form.evaluationDtl && form.evaluationDtl.name
      this.form.souce = form.souce.toString()
      this.form.uploadList = form.attachments.map(i => { i.url = process.env.VUE_APP_BASE_API + i.url; return i })
    },

    // 上传
    handleSuccess(list) {
      // this.form.uploadList.push(list.data)
      this.form.uploadList = list
    },
    // 删除
    handleRemove(list) {
      // this.event.uploadList.splice(this.form.uploadList.indexOf(list.data),1)
      this.form.uploadList = list
    },
    // 上传zip
    handleSuccesszip(list) {
      this.importf.uploadList = list
    },
    // 删除
    handleRemovezip(list) {
      this.importf.uploadList = list
    },
    // 上传图片
    handleSuccessevent(list) {
      if (this.typeText == '延期') {
        this.event.uploadList.push(list.data)
      } else {
        this.event.uploadList = list
      }
    },
    // 删除
    handleRemovevent(list) {
      if (this.typeText == '延期') {
        this.event.uploadList.splice(this.event.uploadList.indexOf(list.data), 1)
      } else {
        this.event.uploadList = list
      }
    },
    doImport() {
      this.importVisible = true
    },
    setComfirmText(arr, key = 'eventDesc') {
      if (arr.length > 2) {
        return `${arr.splice(0, 2).map(i => i[key]).join()}...等`
      } else {
        return arr.map(i => i[key]).join()
      }
    },
    // 批量审核
    doBatchAduit() {
      const objArr = this.crud.selections.filter(i => i.status == 12)
      if (objArr.length == 0) return this.$message.error('当前没有可批量操作的数据!')
      this.$confirm(`确认批量指派审核标题为${this.setComfirmText(objArr)}的数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        crudTEvent.updateAll(objArr.map(i => i.id)).then(res => {
          this.$message({
            type: 'success',
            message: '审核成功'
          })
          this.crud.refresh()
        })
      }).catch(() => {
      })
    },
    //
    doBatchZhiPai() {
      this.zhipaiArr = this.crud.selections.filter(i => i.status == 12 || i.status == 0)
      if (this.zhipaiArr.length == 0) return this.$message.error('当前没有可批量操作的数据!')
      this.$confirm(`确认批量指派标题为${this.setComfirmText(this.zhipaiArr)}的数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.zhipaiBatch = true
        this.assignVisible = true
      }).catch(() => {
      })
    },
    doBatchNoPass() {
      crudTEvent.aduitAll({ eventIds: this.listBatch.map(i => i.id), isPassed: 0, reason: this.passForm.reason, type: this.dialogType }).then(res => {
        this.$message({
          type: 'success',
          message: this.dialogType == 1 ? '复核不通过成功' : '审核不通过成功'
        })
        this.innerVisible = false
        this.crud.refresh()
      })
    },
    // 复核批量
    doBatchFuHe() {
      this.dialogType = 1
      this.listBatch = []
      this.listBatch = this.crud.selections.filter(i => { return (i.status == 8 || i.status == 9 || i.status == 10) && i.rpunit && i.rpunit.id == this.user.dept.id })
      if (this.listBatch.length == 0) return this.$message.error('当前没有可批量操作的数据!')
      this.$confirm(`确认批量复核标题为${this.setComfirmText(this.listBatch)}的数据?`, '提示', {
        confirmButtonText: '通过',
        cancelButtonText: '不通过',
        type: 'warning'
      }).then(() => {
        crudTEvent.aduitAll({ eventIds: this.listBatch.map(i => i.id), isPassed: 1, type: 1 }).then(res => {
          this.$message({
            type: 'success',
            message: '复核通过成功'
          })
          this.crud.refresh()
        })
      }).catch(() => {
        this.innerVisible = true
      })
    },
    // 审批批量
    doBatchShenPi() {
      this.dialogType = 2
      this.listBatch = []
      this.listBatch = this.crud.selections.filter(i => { return (i.status == 5 || i.status == 6 || i.status == 7) })
      if (this.listBatch.length == 0) return this.$message.error('当前没有可批量操作的数据!')
      this.$confirm(`确认批量审核标题为${this.setComfirmText(this.listBatch)}的数据?`, '提示', {
        confirmButtonText: '通过',
        cancelButtonText: '不通过',
        type: 'warning'
      }).then(() => {
        crudTEvent.aduitAll({ eventIds: this.listBatch.map(i => i.id), isPassed: 1 }).then(res => {
          this.$message({
            type: 'success',
            message: '审核通过成功'
          })
          this.crud.refresh()
        })
      }).catch(() => {
        this.innerVisible = true
      })
    },
    onImportSubmit() {
      if (this.importf.souce == '' || this.$refs.zdyUpload.$refs.childUpload.uploadFiles.length == 0) {
        return this.$message.error('请完善信息！')
      }
      this.$refs.zdyUpload.$refs.childUpload.submit()
      // this.importf.file = this.$refs.zdyUpload.$refs.childUpload.$refs['upload-inner'].upload(this.$refs.zdyUpload.$refs.childUpload.uploadFiles[0].raw)
      // this.importf.file =[]
      // this.importf.file = this.$refs.zdyUpload.$refs.childUpload.uploadFiles[0].raw
      // //  this.$refs.zdyUpload.$refs.childUpload.uploadFiles.map(i=>{return this.importf.file.push(i.raw)})
      // //  this.$refs.zdyUpload.$refs.childUpload.submit();
      // this.importf.souce = +this.importf.souce
      // crudTEvent.importZip(this.importf).then(res => {
      //   if (res.code == 200) {
      //     this.$message({
      //       type: 'success',
      //       message: '导入成功'
      //     })
      //     //
      //   } else {
      //     this.$message.error('导入失败')
      //   }
      // })
    },
    async httpRequest(item) {
      this.importfLoading = true
      const fd = new FormData()
      fd.append('file', item.file)
      fd.append('souce', this.importf.souce)
      await crudTEvent.importZip(fd).then(res => {
        this.importfLoading = false
        this.$refs.zdyUpload.$refs.childUpload.clearFiles()
        this.importVisible = false
        this.crud.refresh()
      }).catch(res => {
        this.importfLoading = false
        this.$refs.zdyUpload.$refs.childUpload.clearFiles()
      })
    },
    onDisputeSubmit() {
      if (this.typeText == '延期' && (this.event.extensionTime == undefined || this.event.extensionTime == null)) {
        return this.$message.error('请选择延期日期')
      }
      let imgType = ''
      // this.event.eventId = this.eventId
      if (this.typeText == '处理') {
        this.event.type = 3
        imgType = 2
      }
      if (this.typeText == '延期') {
        this.event.type = 2
        imgType = 3
      }
      if (this.typeText == '争议') {
        this.event.type = 1
        imgType = 5
      }

      if (this.typeText == '延期') {
        this.event.event = {
          id: this.eventId,

          attachments: this.event.uploadList && this.event.uploadList.map(i => { return { url: i, event: { superviseId: this.eventId, id: this.eventId }, superviseId: this.eventId, type: imgType } }) || []
        }
      } else {
        this.event.event = {
          id: this.eventId,

          attachments: this.event.uploadList && this.event.uploadList.map(i => { return { url: i.response.data, event: { superviseId: this.eventId, id: this.eventId }, superviseId: this.eventId, type: imgType } }) || []
        }
      }
      delete this.event.uploadList

      crudTEvent.tObjection(this.event).then(res => {
        // if (res.code == 200) {
        this.$message({
          type: 'success',
          message: '保存成功'
        })
        this.eventVisible = false
        this.crud.refresh()
        //
        // } else {
        //   this.$message.error('保存失败')
        // }
      }).catch(err => {
        this.$message.error(err || '保存失败')
      })
    },
    onAssignSubmit() {
      if (!this.zhipaiBatch) {
        const params = { id: this.eventId, ...this.assignform }
        this.$refs.assignform.validate(async valid => {
          if (valid) {
            crudTEvent.edit(params).then(res => {
              // if (res.code == 200) {
              this.$message({
                type: 'success',
                message: '保存成功'
              })
              this.assignVisible = false
              this.crud.refresh()
            }).catch(err => {
              this.$message.error(err || '保存失败')
            })
          }
        })
      } else {
        const params = { ids: this.zhipaiArr.map(i => i.id), ...this.assignform }
        this.$refs.assignform.validate(async valid => {
          if (valid) {
            crudTEvent.updateAssignAll(params).then(res => {
              // if (res.code == 200) {
              this.$message({
                type: 'success',
                message: '批量指派成功'
              })
              this.assignVisible = false
              this.crud.refresh()
            }).catch(err => {
              this.$message.error(err || '批量指派失败')
            })
          }
        })
      }
    },
    onAgainSubmit() {
      const params = { id: this.eventId, ...this.againform }
      crudTEvent.secondarySupervision(params).then(res => {
        // if (res.code == 200) {
        this.$message({
          type: 'success',
          message: '保存成功'
        })
        this.againVisible = false
        this.crud.refresh()
      }).catch(err => {
        this.$message.error(err || '保存失败')
      })
    },
    // 提交前做的操作
    [CRUD.HOOK.afterValidateCU](crud) {
      crud.form.attachments = []
      if (this.form.uploadList && this.form.uploadList.length > 0) {
        for (const i of this.form.uploadList) {
          if (i.type) {
            crud.form.attachments.push({ event: { id: crud.form.id }, type: i.type, url: i.url.split(process.env.VUE_APP_BASE_API)[1] })
          } else {
            crud.form.attachments.push({ type: 1, event: { id: crud.form.id }, url: i.response && i.response.data || i.url })
          }
        }
      } else {
        this.$message.error('请上传图片')
        return false
      }
    },
    goback() {
      // this.$router.back()
      // window.location.reload()
      this.$router.push('/system/tEvent')
      this.crud.refresh()
      this.showType = 0
    }
  }
}
</script>
<style scoped>
.groupxzzy {
  border: 1px solid #c0c4cc;
  border-radius: 4px;
  min-height: 32px;
  padding: 5px 10px;
  width: 100%
}
.el-select{
  width: 100%;
}
::v-deep .el-upload-list--picture-card .el-upload-list__item,::v-deep .el-upload--picture-card{
  width: 315px;
  height: 215px;
  line-height: 215px;
}
.question-img-box{
  width: 100%;
  display: flex;
  flex-wrap: wrap;
}
.question-img {
  width: 315px;
  height:215px;
  margin-left: 15px;
  margin-bottom: 15px;
}
</style>
